<template>
    <header id="header" class="cms-header">
        <div class="cms-header-logo" style="color: #fff;font-size: 20px;width: 150px;">
            <span>小程序</span><span style="color: #ff0000;margin-left: 5px">统计</span>
        </div>
        <el-select placeholder="点击/输入切换小程序" v-model="applet" filterable @change="switchApplet"
                   size="medium" style="margin-left: 15px">
            <el-option
                    v-for="item in appletList"
                    :key="item.name"
                    :label="item.title"
                    :value="item.name">
            </el-option>
        </el-select>
        <div class="cms-header-user">

            <div class="top-nav">
                <span class="el-dropdown-link" style="margin-right: 10px;color: #fff">
                    欢迎您，{{userInfo.nickname}}
                </span>
            </div>
        </div>
    </header>
</template>
<script>
    import {AppletListAll} from '@/utils/request';
    export default {
        data() {
            return {
                userInfo: this.$storage.get('userinfo'),
                appletList: [],
                applet:this.$storage.get('count_applet_active'),
            }
        },
        created(){
            this.getAppletList();
        },
        methods:{
            switchApplet(val) {
                this.$store.dispatch('setCountAppletActive',val);
                this.$bus.$emit('changList');
            },
            getAppletList() {
                AppletListAll().then((res)=>{
                    if (res.code) {
                        this.$message.error(res.msg);
                    } else {
                        this.appletList = res.data;
                    }
                })
            },
        }
    }
</script>
